package com.depth.viewer.request.http
{
	import com.depth.viewer.request.RequestBaseProxy;
	
	import mx.messaging.messages.HTTPRequestMessage;
	
	public class HttpRequestBase extends RequestBaseProxy
	{
		private var requestUtil:HttpRequestUtil;
		public function HttpRequestBase(url:String)
		{
			super(url);
			requestUtil = new HttpRequestUtil();
		}
		private function resultEventHandle(data:Object):void{
			if(_resultHandle){
				if(_data)
					_resultHandle(data,_data);
				else
					_resultHandle(data);
			}
		}
		private function faultEventHane(info:Object):void{
			if(_faultHandle){
				if(_data)
					_faultHandle(info,_data);
				else
					_faultHandle(info);
			}
		}
		override public function request(methodName:String,... args:Array):void{
			switch(methodName){
				case HTTPRequestMessage.POST_METHOD:
					requestUtil.httpPost(_url,args[0],resultEventHandle,faultEventHane,args[1]?args[1]:HttpParam.CONTENT_TYPE_FORM,args[2]?args[2]:HttpParam.RESULT_FORMAT_TEXT);
					break;
				case HTTPRequestMessage.PUT_METHOD:
					requestUtil.httpPut(_url,args[0],args[1]?args[1]:HttpParam.CONTENT_TYPE_FORM,args[2]?args[2]:HttpParam.RESULT_FORMAT_TEXT,resultEventHandle,faultEventHane);
					break;
				case HTTPRequestMessage.GET_METHOD:
					requestUtil.httpGet(_url,args[0],resultEventHandle,faultEventHane,args[1]?args[1]:HttpParam.RESULT_FORMAT_TEXT);
					break;
				case HTTPRequestMessage.DELETE_METHOD:
					requestUtil.httpDelete(_url,args[0],args[1]?args[1]:HttpParam.CONTENT_TYPE_FORM,args[2]?args[2]:HttpParam.RESULT_FORMAT_TEXT,resultEventHandle,faultEventHane);
					break;
			}
		}
	}
}